<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="__CDN__/assets/layui/layui.js"></script>
  <script src="__CDN__/assets/layui/lay/modules/layer.js"></script>
  <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
  <script src="__CDN__/assets/js/modal.js"></script>
  <link rel="stylesheet" href="__CDN__/assets/layui/css/layui.css">
  <link rel="stylesheet" href="__CDN__/assets/layui/css/modules/layer/default/layer.css">
  <title>年份商城</title>
</head>

<body>
  <link rel="stylesheet" href="__CDN__/assets/regist/demo.css">
  <div class="warp">
    <div class="head">
      注册
    </div>
    <div class="nav flex">
      <div class="item">
        <div class="title" onclick="changeColor(1)">个人注册</div>
        <div class="line"></div>
      </div>
      <div class="item">
        <div class="title title2" onclick="changeColor(2)">企业注册</div>
        <div class="line line2"></div>
      </div>
    </div>
    <div class="layui-form">
    <form method="post">
      <div class="cont">
        <div class="item flex">
          <label for="">手机号</label>
          <input id="mobile" name="mobile" type="text" placeholder="请输入手机号">
        </div>
        <div class="item flex code">
          <label for="">验证码</label>
          <input id="code" type="number" name="code" placeholder="请输入验证码">
          <div class="Code" id="codeBtn"><span id="countdown">获取验证码</span></div>
        </div>
        <div class="item flex">
          <label for="">姓名</label>
          <input id="realname" name="realname" type="text" placeholder="请输入姓名">
        </div>
        <div class="item flex">
          <label for="">身份证号</label>
          <input id="idcard" name="idcard" type="text" placeholder="请输入身份证号">
        </div>
        <div class="item flex">
          <label for="">推荐人</label>
          <input id="recommend" name="recommend" type="text" value="{$recommend}" placeholder="请输入推荐人">
        </div>
        <div class="item flex">
          <label for="">密码</label>
          <input id="password" name="password" type="password" placeholder="输入数字和字母组合密码">
          <div class="image" data-id="1">
            <img src="__CDN__/assets/regist/image/buxianshi.png" alt="">
          </div>
        </div>
        <div class="item flex">
          <label for="">确认密码</label>
          <input id="agenpassword" name="agenpassword" type="password" placeholder="再次输入密码">
          <div class="image" data-id="2">
            <img src="__CDN__/assets/regist/image/buxianshi.png" alt="">
          </div>
        </div>
      </div>
    </form>
    </div>
    <div class="btn" id="registerBtn" lay-filter="sub" lay-submit>立即注册</div>
    <div class="go_download" id="downloadBtn">已注册，去下载</div>
  </div>

  <script type="text/javascript">
    $(function(){
      // 验证码
      $("#countdown").click(function(){
        var sm = $("#countdown").text();
        if (sm=="获取验证码"||sm=="重新发送") {
          var mobile = $("#mobile").val();
          if(mobile==''){
            layer.msg('请输入手机号')
            return false;
          }
          modal.ajax("{:url('send')}",{mobile:mobile},function (res) {
            if(res.code==1){
              layer.msg('验证码已发送');
              var data = 60;
              var dd = setInterval(function(){
                if(data <= 0){
                  $("#countdown").text("重新发送");
                  clearInterval(dd);
                  return;
                }
                data--;
                $("#countdown").text(data+'s');
              },1000)
            }else{
              layer.msg(res.msg)
            }
          });
        }
      });
      $('#downloadBtn').click(function () {
          window.location.href = "https://hbscgw.nfttop123.com";
      })
      $('.image').click(function () {
         var a= $(this).attr('data-id');
         if(a==1){
          var type= $("#password").attr('type');
          if(type=='password'){
            $("#password").attr('type','text');
          }else{
            $("#password").attr('type','password');
          }

         }else{
           var type1= $("#agenpassword").attr('type');
           if(type1=='password'){
             $("#agenpassword").attr('type','text');
           }else{
             $("#agenpassword").attr('type','password');
           }
         }
      })
      // 密码框切换
      $(".eye_btn1").click(function(){
        $(this).hide().siblings("input").attr("type","text").siblings(".eye_btn2").show();
      });
      $(".eye_btn2").click(function(){
        $(this).hide().siblings("input").attr("type","password").siblings(".eye_btn1").show();
      });

      layui.use(['form', 'layer'], function () {
        var form = layui.form,layer = layui.layer,$ = layui.jquery;
        // 登录提交监听
        form.on('submit(sub)', function (data) {

          var mobile = $("#mobile").val();
          var password = $("#password").val();
          var agenpassword = $("#agenpassword").val();
          var recommend = $("#recommend").val();
          var idcard = $("#idcard").val();
          var realname = $("#realname").val();
          var code = $("#code").val();

          if(mobile == ''){
            layer.msg('请输入手机号');
            return false;
          }
          if(code == ''){
            layer.msg('请输入验证码');
            return false;
          }
          if(idcard == ''){
            layer.msg('请输入身份证号');
            return false;
          }
          if(realname == ''){
            layer.msg('请输入姓名');
            return false;
          }
          if(recommend == ''){
            layer.msg('请输入推荐人手机号');
            return false;
          }
          if(password == ''){
            layer.msg('请输入密码');
            return false;
          }
          if(password.indexOf(" ")!=-1){
            layer.msg('密码请勿使用空格');
            return false;
          }
          if(agenpassword == ''){
            layer.msg('请输入确认密码');
            return false;
          }
          var loading = layer.load(1, {shade: [0.1, '#fff']});
          $.post("{:url('regist')}",{mobile:mobile,code:code,password:password,agenpassword:agenpassword,realname:realname,idcard:idcard,recommend:recommend},function(res){
            layer.close(loading);
            if(res.code > 0){
              layer.msg(res.msg,{time:1000,icon:1},function(){
                location.href = "{:url('index/index')}";
              });
            }else{
              layer.msg(res.msg,{time:1000,icon:2});
              // $('.captcha img').attr('src','{:url("verify")}?id='+Math.random());
            }
          });
        })
      })
/*      $("#registerBtn").click(function () {
        var mobile = $("#mobile").val();
        var password = $("#password").val();
        var confirmPassword = $("#confirmPassword").val();
        var recommend = $("#recommend").val();
        var Idcode = $("#Idcode").val();
        var name = $("#name").val();
        var code = $("#code").val();

        if(mobile == ''){
          layer.msg('请输入手机号');
          return false;
        }
        if(code == ''){
          layer.msg('请输入验证码');
          return false;
        }
        if(Idcode == ''){
          layer.msg('请输入身份证号');
          return false;
        }
        if(name == ''){
          layer.msg('请输入姓名');
          return false;
        }
        if(recommend == ''){
          layer.msg('请输入推荐人手机号');
          return false;
        }
        if(password == ''){
          layer.msg('请输入密码');
          return false;
        }
        if(password.indexOf(" ")!=-1){
          layer.msg('密码请勿使用空格');
          return false;
        }
        if(confirmPassword == ''){
          layer.msg('请输入确认密码');
          return false;
        }
        var backUrl = "{:input('backUrl')}";
        modal.ajax('',{mobile:mobile,code:code,password:password,confirmPassword:confirmPassword,name:name,Idcode:Idcode,recommend:recommend},function (res) {
          if(res.status==0){

            layer.msg('注册成功，现去登录',{time:1000,icon:1},);
            setTimeout(function () {
              try {
                var data=window.android.upType();
                if(data==1){
                  location.replace("{:url('login/index')}");
                }
              }catch(e){
                if(backUrl!=''){
                  location.replace("{:url('xiazai/app_dol')}?backUrl="+backUrl);
                }else{
                  location.replace("{:url('xiazai/app_dol')}");
                }

              }
            },1000);

          }else{
            layer.msg(res.msg,{time:1000,icon:2});
          }
        })
      });*/
    });

  </script>
<!--  <script>
    // 切换
    let currentColor = "#0048BF";
    let otherColor = "#333";
    function changeColor(title) {
      let titles = document.getElementsByClassName("title");
      let lines = document.getElementsByClassName("line");
      if (title == 1) {
        titles[0].style.color = '#0048BF';
        titles[1].style.color = '#333';
        lines[0].style.backgroundColor = "#0048BF";
        lines[1].style.backgroundColor = "#fff";
      } else {
        titles[1].style.color = '#0048BF';
        titles[0].style.color = '#333';
        lines[1].style.backgroundColor = "#0048BF";
        lines[0].style.backgroundColor = "#fff";
      }
    }
    const phoneInput = document.getElementById("phone");
    const codeInput = document.getElementById("code");
    const nameInput = document.getElementById("name");
    const IdcodeInput = document.getElementById("Idcode");
    const referenceInput = document.getElementById("reference");
    const passwordInput = document.getElementById("password");
    const confirmPasswordInput = document.getElementById("confirmPassword");
    //点击事件
    const codeBtn = document.getElementById("codeBtn");
    const registerBtn = document.getElementById("registerBtn");
    const downloadBtn = document.getElementById("downloadBtn");
    // 倒计时

    phoneInput.addEventListener("input", function () {
      console.log("确认密码输入框内容已更改:", phoneInput.value);
    });
    codeInput.addEventListener("input", function () {
      console.log("确认密码输入框内容已更改:", codeInput.value);
    });
    nameInput.addEventListener("input", function () {
      console.log("确认密码输入框内容已更改:", nameInput.value);
    });
    IdcodeInput.addEventListener("input", function () {
      console.log("确认密码输入框内容已更改:", IdcodeInput.value);
    });
    referenceInput.addEventListener("input", function () {
      console.log("确认密码输入框内容已更改:", referenceInput.value);
    });
    passwordInput.addEventListener("input", function () {
      console.log("确认密码输入框内容已更改:", passwordInput.value);
    });
    confirmPasswordInput.addEventListener("input", function () {
      console.log("确认密码输入框内容已更改:", confirmPasswordInput.value);
    });
    function startCountdown(duration, displayElementId) {
      var timer = duration;
      var countdownInterval = setInterval(function () {
        document.getElementById(displayElementId).textContent = timer + 's';
        if (&#45;&#45;timer < 0) {
          clearInterval(countdownInterval);
          document.getElementById(displayElementId).textContent = "获取验证码";
        }
      }, 1000);
    }
    // 点击
    codeBtn.addEventListener("click", function () {
      console.log("获取验证码按钮被点击");
      if (phoneInput.value != '') {
        $.ajax({
          url: "https://hbscgw.nfttop123.com/addons/shopro/index/send", // API URL
          type: "POST", // 请求类型（GET、POST等）
          dataType: "json", // 预期服务器返回的数据类型
          headers: {
            "Access-Control-Allow-Origin": "*", // 允许所有域的请求
          },
          data: {
            mobile: phoneInput.value,
            event: 'register'
          },
          success: function (data) { // 请求成功时执行的回调函数
            console.log(data); // 输出响应数据
            startCountdown(60, 'countdown');
          },
          error: function (jqXHR, textStatus, errorThrown) { // 请求失败时执行的回调函数
            console.error("请求失败: " + textStatus + " " + errorThrown);
          }
        });
      }
    });
    registerBtn.addEventListener("click", function () {
      console.log("注册被点击");
      $.ajax({
          url: "https://hbscgw.nfttop123.com/addons/shopro/user.user/smsRegister", // API URL
          type: "POST", // 请求类型（GET、POST等）
          dataType: "json", // 预期服务器返回的数据类型
          headers: {
            "Access-Control-Allow-Origin": "*", // 允许所有域的请求
          },
          data: {
            mobile: phoneInput.value,
            code: codeInput.value,
            password:passwordInput.value,
            recommend:referenceInput.value,
            agenpassword:confirmPasswordInput.value,
            realname:nameInput.value,
            idcard:IdcodeInput.value,
          },
          success: function (data) { // 请求成功时执行的回调函数
            console.log(data); // 输出响应数据
            startCountdown(60, 'countdown');
          },
          error: function (jqXHR, textStatus, errorThrown) { // 请求失败时执行的回调函数
            console.error("请求失败: " + textStatus + " " + errorThrown);
          }
        });
    });
    downloadBtn.addEventListener("click", function () {
      console.log("跳转被点击");
      window.location.href = "https://hbscgw.nfttop123.com/"
    });

  </script>-->
</body>

</html>